//
//  OfflineViewController.m
//  DA_V
//
//  Created by 周季阳 on 15/4/28.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "OfflineViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "OffLineTableViewCell.h"
#import "OfflineListViewController.h"
#import "OffLineView.h"
#import "UpgradeViewController.h"
#import "ZupgradeCell.h"
#import "ZUpgradeViewController.h"
#import "YoungAllData.h"
#import "ListView.h"
#import "GMDCircleLoader.h"

@interface OfflineViewController ()<UIScrollViewDelegate,YoungDelegate,UITextFieldDelegate,ListViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
    int t;
    OffLineView *offView;
    UIImageView *jian1;
    UIImageView *jian2;
    UIImageView *jian3;
    UITableView *lTableView;
    UIView *addView;
    UIButton *screenBtn;
    UIScrollView *zScrollview;
    BOOL zhouB;
    BOOL xuB;
    BOOL LiuB;
    NSString *levelID;
    UITextField *zTextField;
    UITableView *zPageView;
    UIButton *pagesBtn;
    NSMutableArray *arr1;
}
@property (nonatomic ,retain) ListView *listView;
@property(nonatomic,retain)NSMutableArray *zArrayData;
@property (nonatomic , retain) UILabel *levelValue;
//筛选用到的数组
@property(nonatomic,retain)NSMutableArray *zShaiXuanArray;
@end

@implementation OfflineViewController
@synthesize arr,zTableView,levelValue,zArrayData,zShaiXuanArray;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=YES;
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    
    t = 1;
    
    [self initNav];
    navTitle.text = @"下线管理";
    levelID = @"";
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];
    
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate  = self;
    [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];
}
#pragma mark - 下线管理回调
-(void)children:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];

    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {

    zArrayData = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    
    if (zTableView) {
        [zTableView reloadData];
    }else{
    [self initUI];
       
  
    }
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
-(void)singleTap{
    [zTextField resignFirstResponder];
}

#pragma mark - 下限管理回调失败
-(void)requistFail{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 返回
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - initUI
-(void)initUI{
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, navView.bottom, SCREEN_WIDTH, 60)];
    topView.userInteractionEnabled = YES;
    topView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topView];
    
    UILabel *infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,0, 130, 30)];
    
    
    //FatherLevelID"
    //LevelID
    infoLabel.text = [NSString stringWithFormat:@"我的上线:%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"FatherAgent"]];
    infoLabel.font = [UIFont systemFontOfSize:14];
    infoLabel.textAlignment = NSTextAlignmentLeft;
    infoLabel.textColor = [UIColor blackColor];
    [topView addSubview:infoLabel];
    
    UILabel *levelLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,infoLabel.bottom, 64, 30)];
    levelLabel.text = [NSString stringWithFormat:@"等级:%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"FatherLevelName"]];
    levelLabel.font = [UIFont systemFontOfSize:14];
    levelLabel.textAlignment = NSTextAlignmentLeft;
    levelLabel.textColor = [UIColor blackColor];
    [topView addSubview:levelLabel];
    
    UIImageView *myImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"下线管理_0311"]];
    myImage.frame = CGRectMake(SCREEN_WIDTH-113, 15, 103, 30);
    [topView addSubview:myImage];
    
    
    UILabel *myLevelLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 103, 30)];
    myLevelLabel.text = [NSString stringWithFormat:@"我的等级:%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"LevelName"]];
    myLevelLabel.font = [UIFont systemFontOfSize:14];
    myLevelLabel.textAlignment = NSTextAlignmentCenter;
    myLevelLabel.textColor = [UIColor blackColor];
    [myImage addSubview:myLevelLabel];
    
    NSInteger LevelID = [[[NSUserDefaults standardUserDefaults]objectForKey:@"LevelID"] integerValue];
    switch (LevelID) {
        case 2:
            zShaiXuanArray = [[NSMutableArray alloc]initWithObjects:@"一级",@"二级",@"特约" ,nil];
            break;
        case 3:
            zShaiXuanArray = [[NSMutableArray alloc]initWithObjects:@"二级",@"特约" ,nil];
            break;
        case 4:
            zShaiXuanArray = [[NSMutableArray alloc]initWithObjects:@"特约" ,nil];
            break;
        default:
            zShaiXuanArray = [[NSMutableArray alloc]init];
            break;
    }
    
    //add
    
    addView = [[UIView alloc]initWithFrame:CGRectMake(0, topView.bottom+10, SCREEN_WIDTH, 400)];
    addView.userInteractionEnabled = YES;
    addView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:addView];
    
   
    screenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    screenBtn.frame = CGRectMake(10, 10, 107, 29);
    screenBtn.backgroundColor = [UIColor whiteColor];
    [screenBtn setBackgroundImage:[UIImage imageNamed:@"下线管理_031.jpg"] forState:UIControlStateNormal];
    [screenBtn setTitle:@" 筛选" forState:UIControlStateNormal];
    screenBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [screenBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    screenBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [screenBtn addTarget:self action:@selector(clickScreenBtn) forControlEvents:UIControlEventTouchUpInside];
    [addView addSubview:screenBtn];
    
    
    UIImageView *backImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"下线管理_111"]];
    backImage.frame = CGRectMake(10, screenBtn.bottom+10, SCREEN_WIDTH-20, 26);
    backImage.userInteractionEnabled = YES;
    [addView addSubview:backImage];
    NSMutableArray *array ;
    if (SCREEN_WIDTH==320) {
        array = [[NSMutableArray alloc]initWithObjects:@"   销售额",@"     等级",@"   注册时间",@"       未审核", nil];
        
    }else if (SCREEN_WIDTH == 375){
        array = [[NSMutableArray alloc]initWithObjects:@"      销售额",@"        等级",@"     注册时间",@"          未审核", nil];
        
    }else{
        array = [[NSMutableArray alloc]initWithObjects:@"       销售额",@"        等级",@"        注册时间",@"            未审核", nil];
        
    }
    for (int i = 0; i < 4; i++) {
        UIButton *sortBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        if (SCREEN_WIDTH==320) {
            sortBtn.frame = CGRectMake(i*75, 0, 75, 26);
        }else if (SCREEN_WIDTH == 375){
            sortBtn.frame = CGRectMake(i*87, 0, 87, 26);
        }else{
            sortBtn.frame = CGRectMake(i*97, 0, 97, 26);
        }
        sortBtn.backgroundColor = [UIColor clearColor];
        sortBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [sortBtn setTitle:[array objectAtIndex:i] forState:UIControlStateNormal];
        [sortBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        sortBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        sortBtn.tag = i+10;
        [sortBtn addTarget:self action:@selector(clicksortBtn:) forControlEvents:UIControlEventTouchUpInside];
        [backImage addSubview:sortBtn];
        
        
    }
    
    jian1= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"下线管理_222"]];
    
    
    [backImage addSubview:jian1];
    
    jian2= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"下线管理_222"]];
    
    [backImage addSubview:jian2];
    
    jian3= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"下线管理_222"]];
    
    [backImage addSubview:jian3];
    
    if (SCREEN_WIDTH==320) {
        jian1.frame = CGRectMake(55, 11, 9, 4);
        jian2.frame = CGRectMake(55+75, 11, 9, 4);
        jian3.frame = CGRectMake(55+155, 11, 9, 4);
    }else if (SCREEN_WIDTH == 375){
        jian1.frame = CGRectMake(67, 11, 9, 4);
        jian2.frame = CGRectMake(67+87, 11, 9, 4);
        jian3.frame = CGRectMake(67+87+87+5, 11, 9, 4);
    }else{
        jian1.frame = CGRectMake(77, 11, 9, 4);
        jian2.frame = CGRectMake(77+97, 11, 9, 4);
        jian3.frame = CGRectMake(77+97+97+5, 11, 9, 4);
    }
    
    
    UIImageView *backTextView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"下线管理_07"]];
    backTextView.frame = CGRectMake(screenBtn.right+10, 10, 214-33, 29);
    backTextView.userInteractionEnabled = YES;
    [addView addSubview:backTextView];
    
    
    
    zTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 ,214-33-50 , 29)];
    zTextField.tag = 1;
    zTextField.placeholder = @"输入客户姓名/电话";
    zTextField.returnKeyType=UIReturnKeySearch;
    zTextField.font = [UIFont systemFontOfSize:14];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [backTextView addSubview:zTextField];
    zTextField.delegate = self;
    
    UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    clickBtn.frame = CGRectMake(214-33-20, 0 , 30, 30);
    [clickBtn addTarget:self action:@selector(clickCancleBtn) forControlEvents:UIControlEventTouchUpInside];
    clickBtn.backgroundColor = [UIColor clearColor];
    [backTextView addSubview:clickBtn];

    
//    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    if (SCREEN_WIDTH==320) {
//        searchBtn.frame = CGRectMake(screenBtn.right+10, 10, 214-33, 29);
//    }else if (SCREEN_WIDTH == 375){
//        searchBtn.frame = CGRectMake(screenBtn.right+10, 10, 214+22, 29);
//    }else{
//        searchBtn.frame = CGRectMake(screenBtn.right+10, 10, 214-33+94, 29);
//    }
//    searchBtn.backgroundColor = [UIColor clearColor];
//    [searchBtn setTitle:@"   " forState:UIControlStateNormal];
//    searchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//    searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [searchBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [searchBtn setBackgroundImage:[UIImage imageNamed:@"下线管理_07"] forState:UIControlStateNormal];
//    [searchBtn addTarget:self action:@selector(clickSearchBtn) forControlEvents:UIControlEventTouchUpInside];
//    [addView addSubview:searchBtn];
    
    //    UIView *middleView = [[UIView alloc]initWithFrame:CGRectMake(0, searchBtn.bottom+90, SCREEN_WIDTH, 280)];
    //    middleView.userInteractionEnabled = YES;
    //    middleView.backgroundColor = [UIColor whiteColor];
    //    [addView addSubview:middleView];
    
    //    UILabel *myOffline = [[UILabel alloc]initWithFrame:CGRectMake(10,0, 56, 30)];
    //    myOffline.text = @"全部下线";
    //    myOffline.font = [UIFont systemFontOfSize:14];
    //    myOffline.textAlignment = NSTextAlignmentRight;
    //    myOffline.textColor = [UIColor blackColor];
    //    [middleView addSubview:myOffline];
    
    offView = [[OffLineView alloc] initWithFrame:CGRectMake(10, backTextView.bottom+50, SCREEN_WIDTH-20, 40)];
    offView.backgroundColor = [UIColor whiteColor];
    offView.serialNumber.text = @"姓名";
    offView.serialNumber.font = [UIFont systemFontOfSize:14];
    offView.theAgent.text = @"电话";
    offView.theAgent.font = [UIFont systemFontOfSize:14];
    offView.phoneNumber.text = @"状态";
    offView.phoneNumber.font = [UIFont systemFontOfSize:14];
    offView.orderAmount.text = @"销售额";
    offView.orderAmount.font = [UIFont systemFontOfSize:14];
    [addView addSubview:offView];
    
    pagesBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    if (SCREEN_HEIGHT <500) {
        pagesBtn.frame = CGRectMake(self.view.frame.size.width-70,addView.frame.size.height-90-50, 64, 25) ;
    }else{
        pagesBtn.frame = CGRectMake(self.view.frame.size.width-70,addView.frame.size.height-30-50, 64, 25) ;
    }
    pagesBtn.tag = 29;
    [pagesBtn setBackgroundImage:[UIImage imageNamed:@"selectBtn"] forState:UIControlStateNormal];
    [pagesBtn setTintColor:[UIColor blackColor]];
    [pagesBtn setTitle:@"第1页" forState:UIControlStateNormal];
    pagesBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [pagesBtn addTarget:self action:@selector(pageBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [pagesBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];
    pagesBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
    [addView addSubview:pagesBtn];
    if (SCREEN_HEIGHT<500) {
        zTableView = [[UITableView alloc] initWithFrame:CGRectMake(10,offView.bottom, self.view.frame.size.width-19, 120)];
    }else{
        zTableView = [[UITableView alloc] initWithFrame:CGRectMake(10,offView.bottom, self.view.frame.size.width-19, 180)];
    }
    zTableView.delegate = self;
    zTableView.dataSource = self;
    [addView addSubview:zTableView];
    zTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    zTableView.backgroundColor = [UIColor clearColor];
    [zTableView registerClass:[OffLineTableViewCell class] forCellReuseIdentifier:@"cell"];
    zTableView.scrollEnabled = NO;
    [self setExtraCellLineHidden:zTableView];
    
    UIButton *backNewsButto1n = [UIButton buttonWithType:UIButtonTypeCustom];
    backNewsButto1n.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-((0.15625*SCREEN_WIDTH)),SCREEN_WIDTH/2, (0.15625*SCREEN_WIDTH));
    [backNewsButto1n addTarget:self action:@selector(detailViewBackAction1) forControlEvents:UIControlEventTouchUpInside];
    [backNewsButto1n setBackgroundImage:[UIImage imageNamed:@"下线管理_10"] forState:UIControlStateNormal];
    [self.view addSubview:backNewsButto1n];
    NSLog(@"%2f",SCREEN_WIDTH);
    
    UIButton *backNewsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backNewsButton.frame = CGRectMake(SCREEN_WIDTH/2, [UIScreen mainScreen].bounds.size.height-((0.15625*SCREEN_WIDTH)),SCREEN_WIDTH/2, (0.15625*SCREEN_WIDTH));
    [backNewsButton addTarget:self action:@selector(detailViewBackAction) forControlEvents:UIControlEventTouchUpInside];
    [backNewsButton setBackgroundImage:[UIImage imageNamed:@"下线管理_shengji"] forState:UIControlStateNormal];
    [self.view addSubview:backNewsButton];
    
    zhouB = YES;
    LiuB = YES;
    xuB = YES;
    
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [topView addGestureRecognizer:singleTapGestureRecognizer];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    UITouch* touch = [touches anyObject];
    
    NSUInteger numTaps = [touch tapCount];
    
    if (numTaps < 2) {
        lTableView.hidden = YES;
        
        
    }
    
}
#pragma mark - 点击搜索
-(void)clickCancleBtn{
    //调用搜索接口
    if (zTextField.text.length ==11 && [self isPureInt:zTextField.text]) {
        //手机号
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate  = self;
        [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"MobileNumber" andSearchValue:zTextField.text andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];
    }else{
        //客户名称
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate  = self;
        [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"RealName" andSearchValue:zTextField.text andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];
    }
    
    [zTextField resignFirstResponder];
}
#pragma mark - UItextField回调
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    //调用搜索接口
    if (zTextField.text.length ==11 && [self isPureInt:zTextField.text]) {
        //手机号
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate  = self;
        [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"MobileNumber" andSearchValue:zTextField.text andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];
    }else{
        //客户名称
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate  = self;
        [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"RealName" andSearchValue:zTextField.text andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];
    }
    
    [textField resignFirstResponder];
    return YES;
}
#pragma mark - 判断一个字符串是否全是数字
- (BOOL)isPureInt:(NSString *)string{
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    
    int val;
    
    return [scan scanInt:&val] && [scan isAtEnd];
    
}
#pragma mark - 排序
-(void)clicksortBtn:(UIButton *)sender{
    UIButton *btn2 = (UIButton *)[self.view viewWithTag:10];
    UIButton *btn3 = (UIButton *)[self.view viewWithTag:11];
    UIButton *btn1 = (UIButton *)[self.view viewWithTag:12];
    UIButton *btn4 = (UIButton *)[self.view viewWithTag:13];
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    UIButton *btn = (UIButton *)[self.view viewWithTag:sender.tag];
    
        if (sender.tag == 10) {
        if (zhouB)
            {
                YoungAllData *data = [[YoungAllData alloc]init];
                data.delegate  = self;
                [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"1" andSortValue:@"desc" andPage:@"" andPerPage:@""];
                [jian1 setImage:[UIImage imageNamed:@"下线管理_222副本"]];
                zhouB = NO;
            }else{
                YoungAllData *data = [[YoungAllData alloc]init];
                data.delegate  = self;
                [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"1" andSortValue:@"asc" andPage:@"" andPerPage:@""];
                [jian1 setImage:[UIImage imageNamed:@"下线管理_222"]];
                zhouB = YES;
            }
        }else if (sender.tag == 11){
            if (xuB) {
                YoungAllData *data = [[YoungAllData alloc]init];
                data.delegate  = self;
                [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"2" andSortValue:@"desc" andPage:@"" andPerPage:@""];
                [jian2 setImage:[UIImage imageNamed:@"下线管理_222副本"]];
                xuB = NO;
            }else{
                YoungAllData *data = [[YoungAllData alloc]init];
                data.delegate  = self;
                [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"2" andSortValue:@"asc" andPage:@"" andPerPage:@""];

                [jian2 setImage:[UIImage imageNamed:@"下线管理_222"]];
                xuB = YES;
            }
        }else if (sender.tag == 12){
            if (LiuB) {
                YoungAllData *data = [[YoungAllData alloc]init];
                data.delegate  = self;
                [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"3" andSortValue:@"desc" andPage:@"" andPerPage:@""];

             
                [jian3 setImage:[UIImage imageNamed:@"下线管理_222副本"]];
                LiuB = NO;
            }else{
                YoungAllData *data = [[YoungAllData alloc]init];
                data.delegate  = self;
                [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"3" andSortValue:@"asc" andPage:@"" andPerPage:@""];

                [jian3 setImage:[UIImage imageNamed:@"下线管理_222"]];
                LiuB = YES;
            }
        }else{
            YoungAllData *data = [[YoungAllData alloc]init];
            data.delegate  = self;
            [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"4" andSortValue:@"desc" andPage:@"" andPerPage:@""];
        }
        
    
    
    [btn setTitleColor:[self colorWithHexString:@"#EA0057"] forState:UIControlStateNormal];
    
}
#pragma mark - 筛选
-(void)clickScreenBtn{
    if (lTableView) {
        [lTableView reloadData];
        lTableView.hidden = NO;
    }else{
        lTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 39, 107, 30*[zShaiXuanArray count])];
        lTableView.delegate = self;
        lTableView.dataSource = self;
        lTableView.backgroundColor = [self colorWithHexString:@"#5D5D5D"];
        [addView addSubview:lTableView];
        lTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        lTableView.scrollEnabled = YES;
    }
    
}
#pragma mark - 全部
-(void)detailViewBackAction1{
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate  = self;
    [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:@"" andSearchKey:@"" andSearchValue:@"" andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];

}
#pragma mark - 升级申请
-(void)detailViewBackAction{
    UpgradeViewController *upgrade = [[UpgradeViewController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:upgrade animated:YES];
}
#pragma mark - 搜索
-(void)clickSearchBtn{
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (tableView == lTableView) {
        return [zShaiXuanArray count];
    }else if (tableView == zPageView){
        return [arr1 count];
    }
    else{
        if (self.zArrayData.count<t*6) {
       // if (1) {
            if (SCREEN_HEIGHT<500) {
                return self.zArrayData.count-(t-1)*4;
                //return 4;
            }else{
                return self.zArrayData.count-(t-1)*6;
                //return [zArrayData count];
            }
        }else{
            if (SCREEN_HEIGHT<500) {
                return 4;
            }else{
                return 6;
            }
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == lTableView) {
        return 30;
    }else if (tableView == zPageView){
        return 15;
    }
    else{
        return 30;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==lTableView) {
        ZupgradeCell *cell = [[ZupgradeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.titleLabel.text  =[zShaiXuanArray objectAtIndex:indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLabel.backgroundColor = [self colorWithHexString:@"#5D5D5D"];
        return cell;
        
    }else if (tableView == zPageView){
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.textLabel.text = [arr1 objectAtIndex:indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return  cell;
    }
    else{
        
        OffLineTableViewCell *cell = [[OffLineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        
        int ts;
        if (t>1) {
            if (SCREEN_HEIGHT<500) {
                ts = (t-1)*4 + (int)indexPath.row;
            }else{
                ts = (t-1)*6 + (int)indexPath.row;
                NSLog(@"%d",ts);
            }
            
            cell.serialNumber.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:ts] objectForKey:@"RealName"]];
            cell.theAgent.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:ts] objectForKey:@"MobileNumber"]];
            cell.phoneNumber.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:ts] objectForKey:@"AgentStatus"]];
            if ([[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"SellAmount"] isEqual:[NSNull null]]){
            cell.orderAmount.text = @"";
            } else{
            cell.orderAmount.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:ts] objectForKey:@"SellAmount"]];
            }
        }
        else{
            cell.serialNumber.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"RealName"]];
            cell.theAgent.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"MobileNumber"]];
            cell.phoneNumber.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"AgentStatus"]];
            //if ([[[self.arr objectAtIndex:indexPath.row] objectForKey:@"wdl_is_status"] integerValue]== 0) {
            //    cell.state.text = @"未审核";
            //}else if ([[[self.arr objectAtIndex:indexPath.row] objectForKey:@"wdl_is_status"] integerValue] == 1){
            //    cell.state.text = [NSString stringWithFormat:@"%@",[[self.arr objectAtIndex:indexPath.row] objectForKey:@"level_name"]];
            //}else{
            cell.state.text = @"￥125155";
            if ([[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"SellAmount"] isEqual:[NSNull null]]) {
         cell.orderAmount.text = @"";
            } else{
            cell.orderAmount.text = [NSString stringWithFormat:@"%@",[[zArrayData objectAtIndex:indexPath.row] objectForKey:@"SellAmount"]];
            }
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    DetailsController *details = [[DetailsController alloc]init];
    //    details.user_id = [[self.arr objectAtIndex:indexPath.row] objectForKey:@"user_id"];
    //    [self.navigationController pushViewController:details animated:YES];
    if (tableView==lTableView) {
        lTableView.hidden = YES;
        [screenBtn setTitle:[NSString stringWithFormat:@"   %@",[zShaiXuanArray objectAtIndex:indexPath.row]] forState:UIControlStateNormal];
        
        if ([[zShaiXuanArray objectAtIndex:indexPath.row] isEqualToString:@"一级"]) {
            levelID = @"3";
        }else if ([[zShaiXuanArray objectAtIndex:indexPath.row] isEqualToString:@"二级"]){
            levelID = @"4";
        }else{
            levelID = @"5";
        }
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate  = self;
        [data gainChildren:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andLevel:levelID andSearchKey:@"" andSearchValue:@"" andSortKey:@"" andSortValue:@"" andPage:@"" andPerPage:@""];
    }else{
 
        int ts;
                ZUpgradeViewController *offllinelist = [[ZUpgradeViewController alloc] init];
        if (t>1) {
            if (SCREEN_HEIGHT<500) {
                ts = (t-1)*4 + (int)indexPath.row;
            }else{
                ts = (t-1)*6 + (int)indexPath.row;
            }
            offllinelist.AgentIDStr = [[zArrayData objectAtIndex:ts] objectForKey:@"AgentID"];
            [self.navigationController pushViewController:offllinelist animated:YES];
        } else{
        offllinelist.AgentIDStr = [[zArrayData objectAtIndex:indexPath.row] objectForKey:@"AgentID"];
        [self.navigationController pushViewController:offllinelist animated:YES];
        }


    }
}
-(void)pageBtnAction:(UIButton *)sender{
        int multiple = 0;
        if (SCREEN_HEIGHT < 500) {
            multiple = 4;
        }else{
            multiple = 6;
        }
        int a = self.zArrayData.count%multiple;
        int b = 0;
    
        if (a == 0) {
            b = (int)self.zArrayData.count/multiple;
        }else{
            b = (int)self.zArrayData.count/multiple+1;
        }
        arr1 = [[NSMutableArray alloc] init];
        for (int j = 1; j<=b; j++) {
            [arr1 addObject:[NSString stringWithFormat:@"第%d页",j]];
        }
    
    if (self.listView == nil) {
        //listView的高度
        CGFloat f =40;
        self.listView = [[ListView alloc] ShowListView:sender andFloat:f andArray:arr1];
        self.listView.delegate = self;
    }else{
        [self.listView hidenListView:sender];
        [self resetListView];
    }
    
}
//协议方法 用来将值设置成为nil
-(void)releaseValuePost:(ListView *)sender{
    [self resetListView];
}
-(void)btnTitle:(NSString *)aaa{
    
    
    NSString *str1 =  [aaa substringFromIndex:1];
    NSString *str2  = [str1 substringToIndex:1];
    t = [str2 intValue];
    
    [zTableView reloadData];
}
-(void)resetListView{
    self.listView = nil;
}

#pragma mark - 隐藏多余的分割线
-(void)setExtraCellLineHidden: (UITableView *)tableView

{
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
    //
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
